package cloud.hadoop.bds.model.common;

import cloud.hadoop.bds.model.constant.ResultConstant;
import lombok.Builder;
import lombok.Data;


import java.io.Serializable;
import java.util.Optional;


@Data
@Builder
public class Result implements Serializable
{

    // 响应码
    private Integer code;

    // 响应消息
    private String msg;

    // 假token值
    private String token;

    // 响应数据
    private Object data;

    public static Result result(Integer code, String msg, Object data)
    {
        return Result.builder()
                .code(code)
                .msg(msg)
                .data(data)
                .build();
    }

    public static Result tokenResult(Integer code, String token, String msg, Object data)
    {
        return Result.builder()
                .code(code)
                .token(token)
                .msg(msg)
                .data(data)
                .build();
    }


    public static Result success()
    {
        return result(ResultConstant.SUCCESS, ResultConstant.SUCCESS_MSG, Optional.empty());
    }

    public static Result success(String msg, Object data)
    {
        return result(ResultConstant.SUCCESS, msg, data);
    }

    public static Result successToken(String token, String msg, Object data)
    {
        return tokenResult(ResultConstant.SUCCESS, token, msg, data);
    }

    public static Result notFound(String msg, Object data)
    {
        return result(ResultConstant.NOT_FOUND, msg, data);
    }

    public static Result notFound()
    {
        return result(ResultConstant.NOT_FOUND, ResultConstant.NOT_FOUND_MSG, Optional.empty());
    }

    public static Result serverError(String msg, Object data)
    {
        return result(ResultConstant.SERVER_ERROR, msg, data);
    }

    public static Result serverError()
    {
        return result(ResultConstant.SERVER_ERROR, ResultConstant.SERVER_ERROR_MSG, Optional.empty());
    }


    public static Result networkError(String msg, Object data)
    {
        return result(ResultConstant.NETWORK_ERROR, msg, data);
    }

    public static Result networkError()
    {
        return result(ResultConstant.NETWORK_ERROR, ResultConstant.NETWORK_ERROR_MSG, Optional.empty());
    }


    public static Result business(String msg, Object data)
    {
        return result(ResultConstant.BUSINESS_EXCEPTION, msg, data);
    }

    public static Result business()
    {
        return result(ResultConstant.BUSINESS_EXCEPTION, ResultConstant.BUSINESS_EXCEPTION_MSG, Optional.empty());
    }


    public static Result notLogin(String msg, Object data)
    {
        return result(ResultConstant.NOT_LOGIN, msg, data);
    }

    public static Result notLogin()
    {
        return result(ResultConstant.NOT_LOGIN, ResultConstant.NOT_LOGIN_MSG, Optional.empty());
    }


    public static Result argumentError(String msg, Object data)
    {
        return result(ResultConstant.ARGUMENT_ERROR, msg, data);
    }

    public static Result argumentError()
    {
        return result(ResultConstant.ARGUMENT_ERROR, ResultConstant.ARGUMENT_ERROR_MSG, Optional.empty());
    }
}